package com.chenglu.android.restaurant.shop.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chenglu.android.R;
import com.chenglu.android.cart.bean.CartBean;
import com.chenglu.android.common.base.BaseMvpFragment;
import com.chenglu.android.mine.bean.CommonDataBean;
import com.chenglu.android.restaurant.adapter.ShopStoryListAdapter;
import com.chenglu.android.restaurant.bean.CurrentShopsInfoBean;
import com.chenglu.android.restaurant.bean.GoodscategorylisBean;
import com.chenglu.android.restaurant.bean.ReviewTypeCountBean;
import com.chenglu.android.restaurant.bean.ShopReviewPageBean;
import com.chenglu.android.restaurant.mvp.contract.RestaurantShopContract;
import com.chenglu.android.restaurant.mvp.presenter.RestaurantShopPresenter;
import com.chenglu.android.restaurant.shop.ShopPhotoActivity;
import com.chenglu.android.restaurant.shop.details.ShopDetailsActivity;

import butterknife.BindView;
import butterknife.OnClick;

public class ShopFragment extends BaseMvpFragment<RestaurantShopPresenter> implements RestaurantShopContract.View {

    @BindView(R.id.tv_shop_story_name)
    TextView tvShopStoryName;
    @BindView(R.id.rv_shop_story)
    RecyclerView rvShopStory;
    @BindView(R.id.tv_shop_opentime)
    TextView tvShopOpentime;
    @BindView(R.id.tv_shop_businessAddress)
    TextView tvShopBusinessAddress;
    @BindView(R.id.tv_shop_locationDesc)
    TextView tvShopLocationDesc;
    @BindView(R.id.ll_shop_businessLicenseImg)
    LinearLayout llShopBusinessLicenseImg;
    @BindView(R.id.ll_shop_foodLicenseImg)
    LinearLayout llShopFoodLicenseImg;
    @BindView(R.id.tv_shop_deliveryService)
    TextView tvShopDeliveryService;
    @BindView(R.id.tv_shop_deliveryTime)
    TextView tvShopDeliveryTime;
    @BindView(R.id.ll_shop_story)
    LinearLayout llShopStory;
    @BindView(R.id.sv_main)
    NestedScrollView svMain;
    private ShopDetailsActivity activity;

    public static Fragment getInstance(ShopDetailsActivity shopDetailsActivity) {
        ShopFragment evaluateFragment = new ShopFragment();
        evaluateFragment.activity = shopDetailsActivity;
        return evaluateFragment;
    }

    @Override
    protected void initView() {
        tvShopStoryName.setText(activity.currentShopsInfoBean.getData().getStory());
        tvShopOpentime.setText(activity.currentShopsInfoBean.getData().getOpenTime());
        if (activity.currentShopsInfoBean.getData().getDeliveryService() == 0) {
            tvShopDeliveryService.setText("配送服务：达达配送");
        } else {
            tvShopDeliveryService.setText("配送服务：");
        }
        tvShopDeliveryTime.setText("配送时间：" + activity.currentShopsInfoBean.getData().getDeliveryTime());
        tvShopBusinessAddress.setText(activity.currentShopsInfoBean.getData().getAddress());
        tvShopLocationDesc.setText(activity.currentShopsInfoBean.getData().getLocationDesc());

        ShopStoryListAdapter shopStoryListAdapter = new ShopStoryListAdapter(mContext, activity.currentShopsInfoBean.getData().getShopsImageList());
        rvShopStory.setLayoutManager(new GridLayoutManager(mContext, 3));
        rvShopStory.setAdapter(shopStoryListAdapter);


    }


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_store_details_story;
    }

    @Override
    public void getCurrentShopsInfo(CurrentShopsInfoBean bean) {

    }

    @Override
    public void getGoodscategoryList(GoodscategorylisBean bean) {

    }

    @Override
    public void getReviewTypeCount(ReviewTypeCountBean bean) {

    }

    @Override
    public void getShopReviewPage(ShopReviewPageBean bean) {

    }

    @Override
    public void getAddCartShop(CommonDataBean bean) {

    }

    @Override
    public void getShopsCartList(CartBean bean) {

    }

    @Override
    public void getShopCouponreceive(CommonDataBean bean) {

    }

    @OnClick({R.id.ll_shop_businessLicenseImg, R.id.ll_shop_foodLicenseImg})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_shop_businessLicenseImg://营业执照
                Intent intent = new Intent(mContext, ShopPhotoActivity.class);
                intent.putExtra(ShopPhotoActivity.PHOTO, activity.currentShopsInfoBean.getData().getBusinessLicenseImg());
                intent.putExtra(ShopPhotoActivity.TITLE, "营业执照");
                mContext.startActivity(intent);
                break;
            case R.id.ll_shop_foodLicenseImg:
                Intent intent1 = new Intent(mContext, ShopPhotoActivity.class);
                intent1.putExtra(ShopPhotoActivity.PHOTO, activity.currentShopsInfoBean.getData().getFoodLicenseImg());
                intent1.putExtra(ShopPhotoActivity.TITLE, "经营许可");
                mContext.startActivity(intent1);
                break;
        }
    }
}
